package team.com;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.BoundCamera;
import org.anddev.andengine.engine.handler.timer.ITimerCallback;
import org.anddev.andengine.engine.handler.timer.TimerHandler;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.ui.activity.BaseGameActivity;

public class MainActivity extends BaseGameActivity
{   

	private static final Scene tmp = null;
	private BoundCamera _camera;
	private ResourcesManager _RSManager;
	private float CAMERA_WIDTH = 480;
	private float CAMERA_HEIGHT = 320;
	
	@Override
	public Engine onLoadEngine() 
	{
		//khởi tạo camera
		_camera = new BoundCamera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
		
		//khởi tạo engine
		final EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE, 
				new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), _camera
				).setNeedsMusic(true).setNeedsSound(true); 
		engineOptions.getTouchOptions().setRunOnUpdateThread(true);		
		
		return new Engine(engineOptions);
	}


	@Override
	public void onLoadResources() 
	{
		ResourcesManager.prepairManager(mEngine, this, _camera);
		_RSManager = ResourcesManager.getInstance();
	}


	@Override
	public Scene onLoadScene() 
	{			
		return SceneManager.getInstance().createSplashScene();
//		mEngine.registerUpdateHandler(new TimerHandler(0.01f, new ITimerCallback(){
//			
//			Scene tmp = null;
//			
//			@Override
//			public void onTimePassed(TimerHandler pTimerHandler) {
//				// TODO Auto-generated method stub
//				mEngine.unregisterUpdateHandler(pTimerHandler);
//				tmp = SceneManager.getInstance().loadGameScene();
//			}			
//		}));
//		return tmp;
	}


	@Override
	public void onLoadComplete() {
		// TODO Auto-generated method stub

		mEngine.registerUpdateHandler(new TimerHandler(0.01f, new ITimerCallback() {
			
			@Override
			public void onTimePassed(TimerHandler pTimerHandler) {
				// TODO Auto-generated method stub
				mEngine.unregisterUpdateHandler(pTimerHandler);
				mEngine.setScene(SceneManager.getInstance().createMenuScene());
				
			}
		}));				
	}
}
